package study.nzy.com.studydemo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.TextView;

public class WelcomeActivity extends Activity {

    CountDownTimer countDownTimer;
    TextView tv_btn_skip;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        tv_btn_skip = findViewById(R.id.tv_btn_skip);
        tv_btn_skip.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                goLoginPage();
            }
        });

        //构造方法中参数1：总时长，计时结束时间；参数2：tick间隔时间
        countDownTimer = new CountDownTimer(5000,1000) {
            @Override
            public void onTick(long time) {
//                <string name="skip_wait">%d秒跳过</string>
                tv_btn_skip.setText(
getString(R.string.skip_wait,time/1000));
            }

            @Override
            public void onFinish() {
                goLoginPage();
            }
        };

        countDownTimer.start();
    }

    private void goLoginPage() {
        countDownTimer.cancel();
        Intent intent = new Intent(WelcomeActivity.this,LoginActivity.class);
        startActivity(intent);
        finish();
    }
}
